﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Mota.XMLControls
{

    /// <summary>
    /// Represent Time visual control based on DX TimeEdit control
    /// </summary>
    public class DXGuiTime : GuiTime
    {
        /// <summary>
        /// Create TimeEdit control 
        /// </summary>
        public DXGuiTime()
        {
            visualControl = new TimeEdit();
            (visualControl as TimeEdit).EditValueChanged += DXGuiTime_EditValueChanged;
            // The DateTime mask mode with the caret automatic movement feature. 
            //(_visualControl as TimeEdit).Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.DateTimeAdvancingCaret;
        }

        void DXGuiTime_EditValueChanged(object sender, EventArgs e)
        {
            this.ChangeEventCall(null);
        }
        /// <summary>
        /// getter returns Text value of TimeEdit control
        /// setter does nothing
        /// </summary>
        public override string Text
        {
            get
            {
                return (visualControl as TimeEdit).Text;
            }
            set
            {

            }
        }

        /// <summary>
        /// Set editor value by adding DataBinding to DX TimeEdit control on EditValue propertie
        /// </summary>
        /// <param name="valueBinding">main binding with current object values</param>
        public override void SetValue(object valueBinding)
        {
            (visualControl as TimeEdit).DataBindings.Add("EditValue", valueBinding as BindingSource, XmlAttributes["XMLAttribute"], true);
        }

        /// <summary>
        /// dummy object
        /// </summary>
        public override object Binding
        {
            get
            {
                return null;
            }
            set
            {
            }
        }

        public override object GetValue()
        {
            return (visualControl as TimeEdit).EditValue;
        }
    }
}
